package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Stock;
import com.ruoyi.system.domain.TStockin;
import com.ruoyi.system.domain.TStockroom;
import com.ruoyi.system.service.IStockService;
import com.ruoyi.system.service.ITStockinService;
import com.ruoyi.system.service.ITStockroomService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StockGoods;
import com.ruoyi.system.service.IStockGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物品管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/system/goods")
public class StockGoodsController extends BaseController
{
    @Autowired
    private ITStockroomService tStockroomService;
    @Autowired
    private IStockGoodsService stockGoodsService;
    @Autowired
    private ITStockinService tStockinService;


    /**
     * 查询所有入库信息
     *
     * @return
     */

    @GetMapping("/stockinlist")
    public AjaxResult stockinlist(TStockin tStockin)
    {
        //查询所有入库信息
        List<TStockin> list = tStockinService.selectTStockinList(tStockin);
        return success(list);
//        startPage();
//        List<StockGoods> list = stockGoodsService.selectStockGoodsList(stockGoods);
//        return getDataTable(list);
    }



    /**
     * 查询所有仓库信息
     *
     * @return
     */

    @GetMapping("/stocklist")
    public AjaxResult stocklist(TStockroom tStockroom)
    {
        //查询所有店铺
        List<TStockroom> list = tStockroomService.selectTStockroomList(tStockroom);
        return success(list);
//        startPage();
//        List<StockGoods> list = stockGoodsService.selectStockGoodsList(stockGoods);
//        return getDataTable(list);
    }
    /**
     * 查询物品管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockGoods stockGoods)
    {
        startPage();
        List<StockGoods> list = stockGoodsService.selectStockGoodsList(stockGoods);
        return getDataTable(list);
    }

    /**
     * 导出物品管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:goods:export')")
    @Log(title = "物品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockGoods stockGoods)
    {
        List<StockGoods> list = stockGoodsService.selectStockGoodsList(stockGoods);
        ExcelUtil<StockGoods> util = new ExcelUtil<StockGoods>(StockGoods.class);
        util.exportExcel(response, list, "物品管理数据");
    }

    /**
     * 获取物品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:goods:query')")
    @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") Long goodsId)
    {
        return success(stockGoodsService.selectStockGoodsByGoodsId(goodsId));
    }

    /**
     * 新增物品管理
     */
    @PreAuthorize("@ss.hasPermi('system:goods:add')")
    @Log(title = "物品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockGoods stockGoods)
    {
        return toAjax(stockGoodsService.insertStockGoods(stockGoods));
    }

    /**
     * 修改物品管理
     */
    @PreAuthorize("@ss.hasPermi('system:goods:edit')")
    @Log(title = "物品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockGoods stockGoods)
    {
        return toAjax(stockGoodsService.updateStockGoods(stockGoods));
    }

    /**
     * 删除物品管理
     */
    @PreAuthorize("@ss.hasPermi('system:goods:remove')")
    @Log(title = "物品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsIds}")
    public AjaxResult remove(@PathVariable Long[] goodsIds)
    {
        return toAjax(stockGoodsService.deleteStockGoodsByGoodsIds(goodsIds));
    }
}
